﻿// 身份证号码验证
jQuery.validator.addMethod("isIdCardNo",function(value, element){
	var idCard=/^(1[0-9]{17})|(1[0-9]{16}[XYxy]{1})$/;
    return this.optional(element)|| idCard.test(value);
},"请正确输入您的身份证号码");

 // 联系电话(手机/电话皆可)验证	 
 jQuery.validator.addMethod("isPhone",function(value,element){
	var mobile=/^(((13[0-9]{1})|(15[0-9]{1})|18[0-9]{1})+\d{8})$/;
	var tel=/^\d{3,4}-?\d{6,9}$/;
	return this.optional(element)||(tel.test(value)|| mobile.test(value));
},"请输入正确格式的电话、手机格式");

 // 电话分机号验证	 
 jQuery.validator.addMethod("isBranchPhone",function(value,element){
	var branchPhone=/^\d{3,4}-?\d{6,9}-\d+$/;
	return this.optional(element)|| branchPhone.test(value);
},"请输入正确的分机号码，分机号码格式为：区号-电话号-分机号");

// 中文姓名验证 
 jQuery.validator.addMethod("isName",function(value,element){
	var chName=/^[\u4e00-\u9fa5]*·{0,}$/;
	return this.optional(element)|| chName.test(value);
},"请输入正确的中文姓名");

//车牌号验证
jQuery.validator.addMethod("isCarNumber",function(value,element){
	var carNumber=/^([\u4e00-\u9fa5]|[A-Z]){1,}[A-Za-z0-9]{1,}$/;
	return this.optional(element)|| carNumber.test(value);
},"请输入正确的车牌号");

//驾照号验证
jQuery.validator.addMethod("isLicense",function(value,element){
	var driverLicense=/^(([1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3})|([1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}))$/;
	return this.optional(element)|| driverLicense.test(value);
},"请输入正确的驾驶证号");

//邮政编码验证
jQuery.validator.addMethod("isPost",function(value,element){
	var postNumber=/^[0-9]{6}$/;
	return this.optional(element)|| postNumber.test(value);
},"请输入正确的邮政编码");

//QQ号验证
jQuery.validator.addMethod("isQq",function(value,element){
	var qqNumber= /^[1-9]{1}[0-9]{4,}$/;
	return this.optional(element)|| qqNumber.test(value);
},"请输入正确的QQ号");

//IP地址验证
jQuery.validator.addMethod("isIp",function(value,element){
	var ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
	return this.optional(element)|| ip.test(value);
},"请输入正确的IP地址");

//浮点型数字验证
jQuery.validator.addMethod("isFloat",function(value,element){
	var floatNumber = /^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/;
	return this.optional(element)|| floatNumber.test(value);
},"请输入正确的浮点型数字");

//帐号验证
jQuery.validator.addMethod("isAccount",function(value,element){
	var account = /^[^\u4e00-\u9fa5]*$/;
	return this.optional(element)|| account.test(value);
},"帐号中不能包含汉字");
 
//E-mail验证
jQuery.validator.addMethod("isEmail",function(value,element){
	var email = /^[a-zA-Z0-9_]+@[a-zA-Z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return this.optional(element)|| email.test(value);
},"请输入正确的E-mail地址");



//以下为不常用验证

//只能输入中文验证
jQuery.validator.addMethod("isCh",function(value,element){
	var chword = /^[\u4e00-\u9fa5]*$/;
	return this.optional(element)|| chword.test(value);
},"只能输入中文");

//英文名字验证
jQuery.validator.addMethod("isEnName",function(value,element){
	var enName = /^[A-Z]{1}[a-z\s]{1,}$/;
	return this.optional(element)|| enName.test(value);
},"请输入正确的英文名字");

//只能输入英文字母和数字验证
jQuery.validator.addMethod("isEn",function(value,element){
	var enWord = /^[a-zA-Z0-9]*$/;
	return this.optional(element)|| enWord.test(value);
},"只能输入英文和数字");

//国内电话号码验证
jQuery.validator.addMethod("isChPhone",function(value,element){
	var chPhone = /^(\d{3}-\d{8})|(\d{4}-\d{7})$/; 
	return this.optional(element)|| chPhone.test(value);
},"请输入正确的国内电话号码，格式为010-12345678或0431-1234567");

//年龄验证
jQuery.validator.addMethod("isAge",function(value,element){
    function testAge(age){
	   if(age > 120){ return confirm("您输入的年龄大于120岁，确定是这个年龄吗？");}else{return true;}
	}
	var age = /^[1-9]{1}[0-9]{0,}$/; 
	return this.optional(element)|| (age.test(value) ? testAge(value) : false);
},"请输入正确的年龄");
//验证日期格式 YYYY/MM 或YYYY-MM
jQuery.validator.addMethod("isDate", 
		function(value,element){
			var ereg = /^(\d{1,4})(-|\/)(\d{1,2})$/;
			var r = value.match(ereg);
			if (r == null) {
				return false;
			}
			var d = new Date(r[1], r[3] - 1);
			var result = (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3]);
			return this.optional(element) || result;
	}, "请输入正确的日期格式");










